class Solution {
public:
    int singleNonDuplicate(vector<int>& nums) {
        int head = 0, tail = nums.size() - 1;
        while (head < tail) {
            int mid = (head + tail) >> 1;
            if (nums[mid] == nums[mid ^ 1]) {
                head = mid + 1;
            } else {
                tail = mid;
            }
        }
        return nums[head];
    }
};
